package com.liu.HomeWork;

import java.io.IOException;
import java.net.*;

/**
 * 接收端
 */
public class HomeWork02ReceiverA {
    public static void main(String[] args) throws IOException {
        DatagramSocket datagramSocket = new DatagramSocket(6666);
        byte[] buf = new byte[1024];
        DatagramPacket datagramPacket = new DatagramPacket(buf, buf.length);
        datagramSocket.receive(datagramPacket);

        int length = datagramPacket.getLength();
        byte[] data = datagramPacket.getData();
        String string = new String(data, 0, length);
        System.out.println(string);
        if (string.equals("四大名著有哪些")){
        byte[] bytes = "红楼梦，西游记，水浒传，三国演义".getBytes();
        DatagramPacket datagramPacket1 = new DatagramPacket(bytes, bytes.length, InetAddress.getByName("192.168.56.1"), 6667);
        datagramSocket.send(datagramPacket1);
        }else {
            System.out.println("你说的什么");
        }
        datagramSocket.close();
    }
}
